#include <stdio.h>
#include <stdlib.h>

struct stick {
    int l;
    int w;
} s[5010];

int main (int argc, char const* argv[])
{
    int n, c, i, j, t, w, ans;

    scanf("%d", &n);
    while (n--) {
        scanf("%d", &c);
        for (i = 0; i < c; i++) {
            scanf("%d %d", &s[i].l, &s[i].w);
        }

        for (i = 0; i < c-1; i++) {
            for (j = i+1; j < c; j++) {
                if (s[i].l > s[j].l || (s[i].l == s[j].l && s[i].w > s[j].w)) {
                    t = s[i].l; s[i].l = s[j].l; s[j].l = t;
                    t = s[i].w; s[i].w = s[j].w; s[j].w = t;
                }
            }
        }

        ans = 0;
        while (1) {
            for (i = 0; i < c; i++) {
                if (s[i].w != -1) {
                    break;
                }
            }
            
            if (i >= c) break;
            ans++;

            w = 0;
            for (; i < c; i++) {
                if (s[i].w != -1 && (w == 0 || s[i].w >= w)) {
                    w = s[i].w;
                    s[i].w = -1;
                }
            }
        }

        printf("%d\n", ans);
    }

    return 0;
}
